﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Howork
{
    public partial class download : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            DeviceManage dm = new DeviceManage();
            string begin = Request["begin_time"];
            string end = Request["end_time"];
            int type_id = Convert.ToInt32(Request["type_id"]);
            DateTime du_begin = DateTime.Parse(begin);
            DateTime du_end = DateTime.Parse(end);
            List<DeviceUsage> du = dm.GetDeviceUsageHistory(du_begin, du_end, type_id);
            DateTime now = DateTime.Now;
            string year = now.Year.ToString();
            string month = now.Month.ToString();
            string day = now.Day.ToString();
            string hour = now.Hour.ToString();
            string minute = now.Minute.ToString();
            string second = now.Second.ToString();
            string now_time = year + '_' + month + '_' + day + '_' + hour + '_' + minute + '_' + second;
            String fileName = FileAdapter.getCSV(du, now_time+"设备使用记录.csv");
            Page.Response.Clear();
            bool success = FileAdapter.provideCSVDownload(Page.Request, Page.Response, fileName, 1024000);
            if (!success)
                Response.Write("下载文件出错！");
            Page.Response.End();
        }
    }
}